<?php
declare(strict_types=1);
namespace App\Api;

use App\ApiController;
// hook api_grid_use.php

/**
 * @title   表格配置
 * @auth	true
 * @login	true
 * @rank    3
 */
class Grid extends ApiController
{
    // hook api_grid_start.php

    /**
     * @title   读取表格配置
     * @rank    99
     */
    public function action_Index_GET()
    {
        $grid = $this->request->param('grid', '');
        $data = $this->AuthUserGrid->get($this->token['UserID'], $grid);
        empty($data['UserID']) && $data = ['UserID' => $this->token['UserID'], 'grid' => $grid, 'k' => "layout", 'v' => ''];
        $this->response('0000', ['data' => $data]);
    }

    /**
     * @title   设置表格配置
     * @rank    99
     */
    public function action_Index_POST()
    {
        $grid = $this->request->param('grid', '');
        $v = trim($this->request->param('value', ''));

        $this->AuthUserGrid->set($this->token['UserID'], $grid, $v);
        $this->response('0000');
    }

    /**
     * @title   设置表格配置
     * @rank    99
     */
    public function action_Index_DELETE()
    {
        $grid = $this->request->param('grid', '');
        $this->AuthUserGrid->del($this->token['UserID'], $grid);
        $this->response('0000');
    }



    /**
     * @title   取表格过滤规则
     * @rank    99
     */

    public function action_Rule_GET(){
        $grid = $this->request->param('grid','');
        $data = $this->AuthUserGridRule->gets($this->token['UserID'],$grid);

        $this->response('0000',['data'=>$data]);
    }

    /**
     * @title   设置表格过滤规则
     * @rank    99
     */
    public function action_Rule_POST(){
        $grid = $this->request->param('grid','');
        $key = $this->request->param('key','');
        $v = $this->request->param('value','');
        $this->AuthUserGridRule->set($this->token['UserID'],$grid,$key,$v);
        $this->response('0000');
    }
    /**
     * @title   设置表格过滤规则
     * @rank    99
     */
    public function action_Rule_DELETE(){
        $grid = $this->request->param('grid','');
        $key = $this->request->param('key','');
        $this->AuthUserGridRule->del($this->token['UserID'],$grid,$key);
        $this->response('0000');
    }

    // hook api_grid_end.php
}

?>